package org.example.foodplatfrom.controller;


import org.example.foodplatfrom.domain.Result;
import org.example.foodplatfrom.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
public class FileuploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        //把文件内容储存在磁盘上
        String originalfileName = file.getOriginalFilename();
        //保证文件名唯一
        String filename= UUID.randomUUID().toString()+originalfileName.substring(originalfileName.lastIndexOf("."));
        //file.transferTo(new File("C:\\Users\\Administrator\\Desktop\\upload\\"+filename));));
        String url= AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
